import request from '@/utils/request'

export const sendAiMessage = async(body) => {
  const url = process.env.NODE_ENV === 'development' ? `${process.env.VUE_APP_AI_BASE_API}/api/v1/chat/completions` : `${process.env.VUE_APP_AI_BASE_API}/v1/chat/completions`
  const response = await fetch(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    dataType: 'text/event-stream',
    body: JSON.stringify(body)
  })

  if (!response.ok) {
    throw new Error('Network response was not ok')
  }
  return response.body
}

export const getAiList = () => {
  return request({
    url: '/v1/chat/models',
    method: 'get'
  })
}

export const getKeyword = (data) => {
  return request({
    url: '/console/promtHelper/getKeyword',
    method: 'post',
    data
  })
}

export const convertSqlPush = (data) => {
  return request({
    url: '/api/convertSql/push',
    method: 'post',
    data
  })
}
